package com.dzsw.files;

import java.util.Optional;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author sunz
 * @version 1.0
 * @CreateTime 2021-06-02-11:25
 */
public class FilesDemo {

  public static void main(String[] args) throws Exception {
    String filePath = "D:\\works\\company_files\\重庆分光器导入统一库";
    File path = new File(filePath);
    String[] fileNames = path.list((dir, name) -> {
      if (name.startsWith("OBD_Information_")) {
        return true;
      }
      return false;
    });
    for (String fn : fileNames) {
      System.out.println(fn);
    }
    File[] files = path.listFiles(pathname -> {
      if (pathname.getName().startsWith("OBD_Information_")) {
        return true;
      }
      return false;
    });
    for (File f : files) {
      System.out.println(f.getName());
    }
    String line = "";
    int num = 0;
    // read file content
    List<CqImportDataVO> dataList = new ArrayList<>();
    for (File f : files) {
      BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
      while ((line = br.readLine()) != null) {
        if (num > 0) {
          String[] datas = line.split("\t");
          Optional<CqImportDataVO> view = CqImportDataVO.build(datas);
          if (view.isPresent()) {
            dataList.add(view.get());
          }
        }
        num++;
      }
    }
    System.out.println(String.format("num = %s,rows = %s", num, dataList.size()));
  }
}
